<template>
  <div id="Company_base">

    <span>
      <img src="../assets/enterprise.png" alt="" class="bread-icon">
    </span>
    <el-breadcrumb style="display:inline-block">
      <el-breadcrumb-item>
        <span style="font-size:20px;">企业信息</span>
      </el-breadcrumb-item>
      <el-breadcrumb-item>
        <span style="font-size:15px;line-height:20px;">基本信息</span>
      </el-breadcrumb-item>
    </el-breadcrumb>
    <div class="content-wrap">
      <div class="topNav">
        <span class="navLeft">基本信息</span>
        <!-- <span class="navRight">
          <el-button size="small" @click="dragSearch()">搜索</el-button>
        </span>
        <span class="navMid">
          <img class="icon-search" src="../assets/search.png" alt="">
          <el-input v-model="searchData" size="small" placeholder="请输入内容" class="searchInput"></el-input>
        </span> -->
      </div>
      <el-form :inline="true" :model="base_info" label-width="130px" class="form-common">
        <el-form-item label="企业名称">
          <el-input v-model="base_info.name" placeholder="企业名称"></el-input>
        </el-form-item>
        <el-form-item label="所在省市区">
          <el-input v-model="base_info.location" placeholder="所在省市区"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="直属药监局">
          <el-input v-model="base_info.drug_admin" placeholder="直属药监局"></el-input>
        </el-form-item>
        <el-form-item label="法定代表人">
          <el-input v-model="base_info.legal_person" placeholder="法定代表人"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="组织机构代码">
          <el-input v-model="base_info.org_code" placeholder="组织机构代码"></el-input>
        </el-form-item>
        <el-form-item label="企业邮寄地址">
          <el-input v-model="base_info.express_address" placeholder="企业邮寄地址"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="企业注册地址">
          <el-input v-model="base_info.register_address" placeholder="企业注册地址"></el-input>
        </el-form-item>
        <el-form-item label="企业类型">
          <el-input v-model="base_info.type"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="邮编">
          <el-input v-model="base_info.zip_code" placeholder="邮编"></el-input>
        </el-form-item>
        <el-form-item label="生产范围">
          <el-input v-model="base_info.production_range" placeholder="生产范围"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="所属总公司">
          <el-input v-model="base_info.head_company" placeholder="所属总公司"></el-input>
        </el-form-item>
        <el-form-item label="是否法人机构">
          <el-input v-if="base_info.is_legal" value="是"></el-input>
          <el-input v-else value="否"></el-input>
        </el-form-item>
      </el-form>
      <div class="btn-group">
        <el-button>取消</el-button>
        <el-button type="primary" @click="update">更新</el-button>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        adminId: '',
        adminToken: '',
        enterprise: '',
        loading: true,
        base_info: {},
      }
    },
    mounted() {
      this.adminId = this.$store.getters.getInfo.id
      this.adminToken = this.$store.getters.getInfo.token
      this.enterprise = this.$store.getters.getInfo.enterprise

      if (this.enterprise && this.adminToken) {
        this.$http({
          url: './enterprise/' + this.enterprise + '/',
          headers: {
            'Authorization': 'Token ' + this.adminToken
          },
          method: 'get',
        }).then(
          response => {
            //success
            console.log(response)
            if (response.status == '200') {
              this.base_info = response.data.base_info
            }
            this.loading = false
          }
        ).catch(error => {
          console.log(error.response)
          if (error.response.status == 401) {
            this.$message({
              message: error.response.data.detail,
              type: 'warning'
            })
            this.$router.push({
              path: '/login'
            });
          } else if (error.response.status == 400) {
            this.$message({
              message: 'error400',
              type: 'error'
            })
          } else {
            this.$message({
              message: '未知错误',
              type: 'error'
            })
          }
          console.log(error);
        });
      } else {
        this.$message({
          message: '登陆已过期，请重新登陆',
          type: 'warning',
          showClose: true,
        });

      }
    },
    methods: {
      update() {
        if (this.enterprise && this.adminToken) {
          this.$http({
            url: '/enterprise-base-info/' + this.enterprise + '/',
            headers: {
              'Authorization': 'Token ' + this.adminToken
            },
            method: 'put',
            data: this.base_info
          }).then(
            response => {
              this.$message({
                showClose: true,
                type: 'success',
                message: '更新成功'
              });

            }).catch(error => {
            console.log(error.response)
            if (error.response.status == 401) {
              this.$message({
                message: error.response.data.detail,
                type: 'warning'
              })
              this.$router.push({
                path: '/login'
              });
            } else if (error.response.status == 400) {
              this.$message({
                message: 'error400',
                type: 'error'
              })
            } else {
              this.$message({
                message: '未知错误',
                type: 'error'
              })
            }
            console.log(error);
          });
        } else {
          this.$message({
            showClose: true,
            type: 'warning',
            message: '登陆已过期'
          });
        }
      }
    }

  }

</script>

<style scoped>
  #Company_base>>>.el-form-item__content {
    width: 220px;
  }

</style>
